home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / prg_bar.exe / CALC.CPP < prev    next >
C/C++ Source or Header  |  1992-08-30  |  5KB  |  221 lines

  1. // This is an example of a progress bar.
  2. //
  3. // Modified THERMO.ZIP in the C++ lib to work with TURBO VISION
  4. // and fixed a small bug.
  5. //
  6. // Author: Jay Perez.
  7.  
  8. #define Uses_TBackground
  9. #define Uses_TListBox
  10. #define Uses_TMenu
  11. #define Uses_TMenuBar
  12. #define Uses_TMenuItem
  13. #define Uses_TScrollBar
  14. #define Uses_TStaticText
  15. #define Uses_TStatusDef
  16. #define Uses_TStatusItem
  17. #define Uses_TStatusLine
  18. #define Uses_TStringCollection
  19. #define Uses_MsgBox
  20. #define Uses_TEventQueue
  21. #define Uses_TApplication
  22. #define Uses_TRect
  23. #define Uses_TDeskTop
  24. #define Uses_TView
  25. #define Uses_TWindow
  26. #define Uses_TDialog
  27. #define Uses_TButton
  28. #define Uses_StaticText
  29. #define Uses_TSItem
  30. #define Uses_TLabel
  31. #define Uses_TInputLine
  32. #define Uses_TEvent
  33. #define Uses_TKeys
  34. #define Uses_TDrawBuffer
  35. #define Uses_TStreamableClass
  36. #define Uses_TStreamable
  37.  
  38. #include <tv.h>
  39. __link( RView )
  40. __link( RDialog )
  41. __link( RButton )
  42. #include <mem.h>                       // memset
  43.  
  44. #include <dos.h>
  45. #include <stdio.h>
  46. #include <string.h>
  47. #include <stdlib.h>
  48. #include <ctype.h>
  49. #include <strstrea.h>
  50. #include <iomanip.h>
  51. #include <conio.h>
  52.  
  53. #include "tprogbar.h"
  54.  
  55. const int sampleIterations = 21 ;
  56.  
  57. const cmAboutCmd   = 100;  // User selected menu item 'About'
  58. const cmStatusCmd  = 101;  // User selected menu item 'Progress Bar'
  59.  
  60.  
  61. //========================================================================
  62.  
  63. class myProgress : public TProgressBar
  64. {
  65.      public :
  66.      myProgress(TRect& r, unsigned long iters ) :
  67.         TProgressBar( r , iters ){};
  68.      virtual void mainProcess( void );
  69. };
  70.  
  71. myProgress *bar ;
  72.  
  73. //========================================================================
  74.  
  75. class TMyApplication : public TApplication
  76. {
  77.      public:
  78.      TMyApplication();
  79.      static TMenuBar *initMenuBar(TRect);
  80.      void handleEvent(TEvent &);
  81.      private:
  82.      void aboutDlg();
  83.      void statusDlg();
  84. };
  85.  
  86. //========================================================================
  87.  
  88. TMyApplication::TMyApplication() :
  89. TProgInit(&TApplication::initStatusLine,&TMyApplication::initMenuBar,
  90.      &TApplication::initDeskTop)
  91. {
  92. }
  93.  
  94. //========================================================================
  95.  
  96. TMenuBar *TMyApplication::initMenuBar(TRect bounds)
  97. {
  98.      bounds.b.y = bounds.a.y + 1;
  99.      return(new TMenuBar(bounds,
  100.                 new TMenu(
  101.                      *new TMenuItem("~A~bout",cmAboutCmd,kbAltA,hcNoContext,0,
  102.                           new TMenuItem("~P~rogress Bar",cmStatusCmd,kbAltL,hcNoContext,0)))));
  103. }
  104.  
  105. //========================================================================
  106.  
  107. void TMyApplication::handleEvent(TEvent &event)
  108. {
  109.      TApplication::handleEvent(event);
  110.  
  111.      if (event.what == evCommand)
  112.      {
  113.           switch (event.message.command)
  114.           {
  115.           case cmAboutCmd:
  116.           {
  117.                 aboutDlg();
  118.                 clearEvent(event);
  119.                 break;
  120.           }
  121.           case cmStatusCmd:
  122.           {
  123.                 statusDlg();
  124.                 clearEvent(event);
  125.                 break;
  126.           }
  127.           }
  128.      }
  129. }
  130.  
  131. //========================================================================
  132.  
  133. void TMyApplication::aboutDlg()
  134. {
  135.      TDialog *pd = new TDialog(TRect(0,0,35,12),"About");
  136.      if (pd)
  137.      {
  138.         pd->options |= ofCentered;
  139.         pd->insert(new TStaticText(TRect(1,2,34,7),
  140.                 "\003Turbo Vision Example\n\003\n"
  141.                      "\003Creating a Progress Bar\n\003\n"));
  142.           pd->insert(new TButton(TRect(3,9,32,11),"~O~k",cmOK,bfDefault));
  143.  
  144.         if (validView(pd) != 0)
  145.         {
  146.                 deskTop->execView(pd);
  147.  
  148.             destroy(pd);
  149.         }
  150.      }
  151. }
  152.  
  153. //========================================================================
  154.  
  155. void TMyApplication::statusDlg()
  156. {
  157.      TView *tv;
  158.  
  159.      TDialog *pd = new TDialog( TRect( 10, 3, 69, 11 ), "Please Wait" ) ;
  160.      if (pd) {
  161.  
  162.      pd->options |= ofFirstClick;
  163.      pd->options |= ofCentered;
  164.  
  165.      TRect r = TRect(4,4,25,6) ;
  166.      tv = new TButton(r, "~S~tart", cmOK, bfNormal | bfBroadcast  ) ;
  167.      tv->options &= ~ofSelectable;
  168.      pd->insert( tv );
  169.  
  170.      r = TRect(34,4,55,6) ;
  171.      tv = new TButton( r, "~C~ancel", cmCancel, bfNormal);
  172.      pd->insert( tv );
  173.  
  174.      bar = new myProgress( TRect( 4, 2, 55, 3 ), 0 ) ;
  175.  
  176.      pd->insert( ( TView * ) bar ) ;
  177.  
  178.      if( TProgram::application->validView( pd ) != 0 ) {    // If it's valid...
  179.          TProgram::deskTop->execView( pd ) ;
  180.          TObject::destroy( pd ) ;
  181.      }
  182.      }
  183.      return ;
  184. }
  185.  
  186. //========================================================================
  187.  
  188. int main(void)
  189. {
  190.      TMyApplication myApplication;
  191.  
  192.      myApplication.run();
  193.  
  194.      return 0;
  195. }
  196.  
  197. //========================================================================
  198.  
  199. void myProgress::mainProcess( void )
  200. {
  201.  
  202.      // Place your processing logic here...
  203.  
  204.      unsigned long cnt = 0 ;
  205.  
  206.      setMaxIter( sampleIterations ) ;   // set maximum number of iterations...
  207.                                                     // do it here or on the constructor ...
  208.                                                     // or both.
  209.  
  210.      for( int x = 0; x < sampleIterations; x++ )
  211.      {
  212.           setCurIter( ++cnt );         // set the current iteration count & update
  213.           delay(500);
  214.      }
  215.  
  216.      delay(500);
  217.      message(owner,evCommand,cmOK,this);// close dialog box
  218. }
  219.  
  220. //========================================================================
  221.